<template>
  <a-form ref="formRef"  :model="form" :rules="rules"  >
    <a-card style="margin-bottom: 15px" size="small">

      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">任务基本信息</a-divider>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="任务ID" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="20230530NO00019" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="任务名称" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="报销单审核 - 李四" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="当前节点" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="财务初审" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="优先级" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="高" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="申请人" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="黄晓霞" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="申请人部门" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="Q武汉爱家国际华城" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>


      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="联系方式" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="13941188888" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="提交时间" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="2023-05-30 09:24:47" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="要求完成日期" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="2023-06-30" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>


      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="工单编号" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="TD20230530NO00051" disabled="true"/>
          </a-form-item>
        </a-col>

      </a-row>

      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">报销详情</a-divider>

      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="报销单号" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="ER20230530NO00019" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="报销类型" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="差旅费" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="报销事由" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="项目采购" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="费用归属项目" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="部门公共费用" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="报销周期" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="三个月" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="总金额(含税)" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="1000（￥）" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>


      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="已预付款项" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="300（￥）" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="应付金额" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="700（￥）" disabled="true"/>
          </a-form-item>
        </a-col>

      </a-row>

      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">费用明细列表</a-divider>

      <a-table
          size="small"
          :dataSource="productList"
          :columns="productColumns"
          rowKey="id"
          bordered
          :loading="productTableLoading"
          :pagination="false"
      >

        <template #bodyCell="{ text, record, column }">

          <template v-if="column.dataIndex === 'sumValue'">
        <span style="color: red;font-weight: bolder">
            {{text}}
        </span>

          </template>

        </template>


      </a-table>


      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">付款信息</a-divider>

      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="收款类型" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="个人账户" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="收款账户名" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="黄晓霞" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="开户银行" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="大连银行" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="银行账号" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="622383*******123456" disabled="true"/><span style="padding-left: 10px"></span> <a-button @click="showUploadForm" type="primary" size="small">复制</a-button>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="银行卡类型" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="储蓄卡" disabled="true"/>
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item claim label="付款备注" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="全额付款" disabled="true"/>
          </a-form-item>
        </a-col>
      </a-row>


      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item claim label="付款方式" :label-col="{ span: 8 }" class="smart-query-form-item">
            <a-input style="width: 80%" value="现金" disabled="true"/>
          </a-form-item>
        </a-col>


      </a-row>


      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">附件列表</a-divider>
      <a-row class="smart-table-btn-block">
        <div class="smart-table-operate-block">
          <a-button @click="showUploadForm" type="primary" size="small"> 上传文件
          </a-button>
        </div>
      </a-row>
      <a-table
          size="small"
          :dataSource="fileList"
          :columns="fileColumns"
          rowKey="id"
          bordered
          :loading="fileTableLoading"
          :pagination="false"
      >
        <template #bodyCell="{ text, record, column }">
          <template v-if="column.dataIndex === 'businessType'">
         <span v-if="text === '发票类'">
          <a-tag color="red">
            {{text}}
          </a-tag>
        </span>
            <span v-if="text === '业务凭证类'">
             <a-tag color="blue">
            {{text}}
          </a-tag>
        </span>
          </template>





          <template v-if="column.dataIndex === 'action'">
            <div class="smart-table-operate">
              <a-button @click="download(record)" type="link">下载</a-button>
              <a-button v-if="record.actionFlag" @click="onDelete(record)" type="link">删除</a-button>
            </div>
          </template>
        </template>

      </a-table>

      <a-divider style="font-size: unset;font-weight: bold;border-color: #dedede" orientation="left">审核信息</a-divider>
      <a-row :gutter="24" class="smart-query-form-row">
        <a-col :span="8">
          <a-form-item :label-col="{ span: 8 }" label="意见类型" lclass="smart-query-form-item">
            <a-select v-model:value="queryForm.status" style="width: 80%" :showSearch="true" :allowClear="true" placeholder="意见类型">
            <a-select-option v-for="item in statusList" :key="item" :value="item">
              {{ item }}
            </a-select-option>
            </a-select>

            <span style="padding-left: 10px"></span>
            <a-button @click="showUploadForm" type="primary" size="small"> 补充附件
              </a-button>

          </a-form-item>

        </a-col>

        <a-col :span="20">
          <a-form-item :label-col="{ span: 3 }" label="意见内容" lclass="smart-query-form-item">
            <a-textarea v-model:value="form.remark" :rows="2" style="width: 200%" />
          </a-form-item>
        </a-col>


      </a-row>

      <div style="text-align: right; padding-right: 20px; padding-top: 20px; padding-bottom: 20px">

        <a-space >
          <a-button  class="ant-btn-primary" >审批通过</a-button>
          <a-button class="ant-btn-primary" >审批驳回</a-button>
          <a-button  class="ant-btn-primary">转派审核</a-button>
          <a-button class="ant-btn-primary" >保存</a-button>
        </a-space>
      </div>
    </a-card>
  </a-form>

</template>

<script setup>
import {onMounted, reactive, ref, watch} from "vue";
import {useRoute, useRouter} from "vue-router";
import {SmartLoading} from "/@/components/framework/smart-loading";
import {smartSentry} from "/@/lib/smart-sentry";
import {useUserStore} from "/@/store/modules/system/user";
import {message, Modal} from "ant-design-vue";
import DictSelect from '/@/components/support/dict-select/index.vue';

const statusList = ref(['同意通过','需补充材料','驳回重提','转派审核']);
const activeKey = ref(['1', '2', '3', '4', '5', '6', '7']);
const customStyle = 'background:white; border-radius: 4px;border: 1;overflow: hidden';
const windowHeight = ref(window.innerHeight);

const productTableLoading = ref(false);
const fileTableLoading = ref(false);
const exceptionTableLoading = ref(false);
const workExperienceTableLoading = ref(false);

const queryFormState = '';

const productColumns = ref([

  {
    title: '费用子类型',
    dataIndex: 'type',
    ellipsis: true,
  },
  {
    title: '发生日期',
    dataIndex: 'date',
    ellipsis: true,
  },

  {
    title: '消费金额',
    dataIndex: 'price',
    ellipsis: true,
  },
  {
    title: '数量',
    dataIndex: 'cnt',
    ellipsis: true,
  },
  {
    title: '单价',
    dataIndex: 'uprice',
    ellipsis: true,
  },

  {
    title: '备注',
    dataIndex: 'remark',
    ellipsis: true,
  },
  {
    title: '报销凭证(附件)',
    dataIndex: 'file',
    ellipsis: true,
  },
  {
    title: '审核状态',
    dataIndex: 'status',
    ellipsis: true,
  },

  {
    title: '合计',
    dataIndex: 'sumValue',
    ellipsis: true,

  },

]);
const fileColumns = ref([

  {
    title: '附件类型',
    dataIndex: 'businessType',
    ellipsis: true,
  },
  {
    title: '附件名称',
    dataIndex: 'fileName',
    ellipsis: true,
  },

  {
    title: '附件大小',
    dataIndex: 'fileSize',
    ellipsis: true,
  },
  {
    title: '上传时间',
    dataIndex: 'createTime',
    ellipsis: true,
  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    width: 200,
  },
]);
const exceptionColumns = ref([

  {
    title: '异常状态',
    dataIndex: 'status',
    ellipsis: true,
  },
  {
    title: '异常内容',
    dataIndex: 'content',
    ellipsis: true,
  },

  {
    title: '解决方案',
    dataIndex: 'solution',
    ellipsis: true,
  },
  {
    title: '创建人',
    dataIndex: 'createUser',
    ellipsis: true,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    ellipsis: true,
  },
  {
    title: '关闭时间',
    dataIndex: 'closeData',
    ellipsis: true,
  },
]);
const workExperienceColumns = ref([

  {
    title: '访谈状态',
    dataIndex: 'status',
    ellipsis: true,
  },
  {
    title: '上家单位名称',
    dataIndex: 'companyName',
    ellipsis: true,
  },

  {
    title: '在职起始时间',
    dataIndex: 'startDate',
    ellipsis: true,
  },
  {
    title: '在职结束时间',
    dataIndex: 'endDate',
    ellipsis: true,
  },
  {
    title: '岗位',
    dataIndex: 'post',
    ellipsis: true,
  },
  {
    title: '联系人',
    dataIndex: 'contacts',
    ellipsis: true,
  },
  {
    title: '联系人电话',
    dataIndex: 'contactsPhone',
    ellipsis: true,
    width: 200,
  },
  {
    title: '联系人岗位',
    dataIndex: 'contactsPost',
    ellipsis: true,
  },
  {
    title: '与被调查人关系',
    dataIndex: 'relationship',
    ellipsis: true,
  },
  {
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
    width: 90,
  },
]);


const productList = ref([]);
const fileList = ref([]);
const exceptionList = ref([]);
const workExperienceList = ref([]);

onMounted(() => {
  getOne();
});

window.addEventListener('resize', function () {
  windowHeight.value = window.innerHeight;
});

let ticket = {
  code: undefined,
  status: undefined,
}
let ticketTask = {
  handlerName: undefined,
  id: undefined,
  taskName: undefined,
  ticketId:undefined,
}
let surveyResutVO = {
  result: undefined
}

let bi = {
  ticketVO: ticket,
  ticketTaskVO: ticketTask,
  biCreate: undefined,
  source: undefined,
  mokoStatus: undefined,
  createTime: undefined,
  name: undefined,
  phone: undefined,
  idCardType: undefined,
  idCard: undefined,
  orgId: undefined,
  departmentId: undefined,
  postId: undefined,
  id: undefined,
  actionFlag: undefined,
  surveyResutVO: surveyResutVO,
  biReport: undefined,
  propose: undefined,
  departmentValue: undefined,
  departmentPathName: undefined,
  contractSubjectId: undefined,
  blackStatus:undefined,
  blackStatusValue:undefined,
  blackAction:undefined,
}

let form = reactive({...bi});
// 查询表单form
let queryForm = reactive({...queryFormState});
let TabactiveKey = "";

const route = useRoute();

let backPath;

async function getOne() {
  try {
    SmartLoading.show();
    let param = {
      id: route.query.id,
      ticketTaskId: route.query.ticketTaskId
    }
    backPath = route.query.backPath;
    queryForm = route.query.queryForm;
    TabactiveKey = route.query.TabactiveKey;




      productList.value = [
        {
          "id": 11,
          "type": "交通",
          "date": "2023-04-02 19:32:00",
          "price": "1000（￥）",
          "cnt": "10",
          "uprice": "100（￥）",
          "remark": "机场到客户现场",
          "file": "发票.png",
          "status": "处理中",
          "sumValue": "1000（￥）"

        },
        {
          "id": 12,
          "type": "住宿",
          "date": "2023-04-02 19:32:00",
          "price": "800（￥）",
          "cnt": "4",
          "uprice": "200（￥）",
          "remark": "如家",
          "file": "发票.png",
          "status": "处理中",
          "sumValue": "800（￥）"
        }
      ];
      fileList.value = [
        {
          "id": 4,
          "fileId": 82,
          "businessId": 4,
          "businessType": "发票类",
          "fileName": "打车发票.pdf",
          "createUserId": 1,
          "actionFlag": true,
          "fileSize": "251.73 KB",
          "createTime": "2023-04-02 19:32:00",
          "code": null
        },
        {
          "id": 4,
          "fileId": 82,
          "businessId": 4,
          "businessType": "业务凭证类",
          "fileName": "酒店发票.pdf",
          "createUserId": 1,
          "actionFlag": true,
          "fileSize": "251.73 KB",
          "createTime": "2023-04-02 19:32:00",
          "code": null
        }
      ] ;
      exceptionList.value = res.data.biExceptionList;
      workExperienceList.value = res.data.workExperienceList;


    if ('exception' === form.ticketVO.status && form.actionFlag) {
      exceptionColumns.value.push({
        title: '操作',
        dataIndex: 'action',
        fixed: 'right',
        width: 90,
      },)
    }


  } catch (err) {
    smartSentry.captureError(err);
  } finally {
    SmartLoading.hide();
  }
}

const router = useRouter();

function close() {

  useUserStore().closeTagNav(route.meta.id.toString(), false);
  router.push({
    path: backPath,
    query: {queryForm: queryForm, TabactiveKey: TabactiveKey},
  });
}

async function termination() {
  SmartLoading.show();
  try {
    await ticketApi.termination(form.ticketTaskVO.id);
    message.success('操作成功');
  } catch (err) {
    smartSentry.captureError(err);
  } finally {
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({path: backPath});
  }
}


async function download(data) {
  try {
    await fileApi.downLoadFile(data.fileName, data.fileId);
  } catch (e) {
    smartSentry.captureError(e);
  }
}


//确认删除
function onDelete(data) {
  Modal.confirm({
    title: '提示',
    content: '确定要删除选吗?',
    okText: '删除',
    okType: 'danger',
    onOk() {
      deleteFile(data);
    },
    cancelText: '取消',
    onCancel() {
    },
  });
}

async function deleteFile(data) {
  try {
    await businessFileApi.delete(data.id);
    message.success('删除成功');
    queryFileData();
  } catch (e) {
    smartSentry.captureError(e);
  }
}

async function queryFileData() {
  fileTableLoading.value = true;
  try {
    let queryResult = await biApi.findFileListByBiId(form.id);
    fileList.value = queryResult.data;
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    fileTableLoading.value = false;
  }
}

const fileFormRef = ref();

function showUploadForm() {
  fileFormRef.value.show(form.id);
}

const workExperienceformRef = ref();

function showWorkExperienceForm(data) {
  workExperienceformRef.value.show(data, form.id);
}

const interviewformRef = ref();

function showInterviewForm(data) {
  data.name = form.name;
  data.phone = form.phone;
  data.idCardType = form.idCardType;
  data.idCard = form.idCard;
  data.actionFlag=form.actionFlag;
  interviewformRef.value.show(data);
}

async function queryWorkExperienceData() {
  workExperienceTableLoading.value = true;
  try {
    let queryResult = await biApi.findWorkExperienceByBiId(form.id);
    workExperienceList.value = queryResult.data;
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    workExperienceTableLoading.value = false;
  }
}


async function queryExceptionData() {
  exceptionTableLoading.value = true;
  try {
    let queryResult = await biApi.findExceptionByBiId(form.id);
    exceptionList.value = queryResult.data;
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    exceptionTableLoading.value = false;
  }
}



const exceptionformRef = ref();

function showExceptionForm(data) {
  exceptionformRef.value.show(form.ticketTaskVO.id, data);
}

async function save() {
  if ("artificial" === form.ticketTaskVO.taskName) {
    SmartLoading.show();
    try {
      form.biId = form.id;
      await biApi.interviewSave(form);
      message.success('操作成功');
      SmartLoading.hide();
    } catch (err) {
      smartSentry.captureError(err);
      SmartLoading.hide();
    }
  }

}
function onSubmit() {
  if ("exception" === form.ticketTaskVO.taskName) {
    let re = true;
    for (const e of exceptionList.value) {
      if ('open' === e.status) {
        re = false;
        break;
      }
    }
    if (re) {
      exceptionComplete();
    } else {
      message.error('异常没有全部关闭，不能提交');
    }

    return;
  }
  if ("artificial" === form.ticketTaskVO.taskName) {
    checkSubmit();
    return;
  }
  message.error('此工单出问题了，不能被提交');
}

const rules = {
  propose: [{ required: true, message: '人事远程交付中心建议 必填' }],
  contractSubjectId: [{ required: true, message: '合同主体 必填' }],
};
// 组件ref
const formRef = ref();
async function checkSubmit() {
  try {
    await formRef.value.validateFields();
    interviewComplete();
  } catch (err) {
    console.log(err)
    message.error('参数验证错误，请仔细填写表单数据!');
  }
}


async function interviewComplete() {

  SmartLoading.show();
  try {
    form.biId = form.id;
    await ticketApi.interviewComplete(form.ticketTaskVO.id, form);
    message.success('操作成功');
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({path: backPath});
  } catch (err) {
    smartSentry.captureError(err);
    SmartLoading.hide();
  }
}

async function exceptionComplete() {
  SmartLoading.show();
  try {
    form.biId = form.id;
    await ticketApi.exceptionComplete(form.ticketTaskVO.id,form);
    message.success('操作成功');
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({ path: backPath });
  } catch (err) {
    smartSentry.captureError(err);
    SmartLoading.hide();
  }
}

function exceptionfo(value) {
  if ("update" === value) {
    queryExceptionData();
  } else {
    close();
  }
}


const surveyResutFormRef = ref();

function showSurveyResut() {
  surveyResutFormRef.value.showModal(form.surveyResutVO);
}

const artificialFormRef = ref();

function showArtificial() {
  artificialFormRef.value.showModal(form);
}


function downloadWorkExperienceTemplate() {
  if (form.workExperienceTemplate) {
    handleDownload2(form.workExperienceTemplate);
  } else {
    message.error('暂无工作履历模板，请先配置');
  }
}

async function handleDownload2(file) {
  try {
    await fileApi.downLoadFile(file.fileName, file.id);
  } catch (e) {
    smartSentry.captureError(e);
  }
}

async function handleDownload(file) {
  try {
    await fileApi.downLoadFile(file.fileName, file.fileId);
  } catch (e) {
    smartSentry.captureError(e);
  }
}

async function handleDownload3(file) {
  try {
    await fileApi.viewFile(file.fileName, file.id);
  } catch (e) {
    smartSentry.captureError(e);
  }
}

async function handleDownload4(file) {
  try {
    await fileApi.viewFile(file.fileName, file.fileId);
  } catch (e) {
    smartSentry.captureError(e);
  }
}


let accept = ".xlsx";

function checkFileType(file) {
  const name = file.name;
  let array = new Array();
  array = name.split(".");
  const fileType = '.' + array[array.length - 1];
  const fts = accept.split(",");

  if (!fts.includes(fileType)) {
    //格式不支持
    return false;
  }
  return true;
}

function checkFileSize(file) {
  let maxSize = 5;
  const isLimitSize = file.size / 1024 / 1024 < maxSize;
  if (!isLimitSize) {
    //文件过大
    return false;
  }
  return true;
}

const wetfileList = ref([]);
const customRequest = async (options) => {
  if (!checkFileType(options.file)) {
    return message.error('不支持此格式的文件');
  }
  if (!checkFileSize(options.file)) {
    return message.error(`上传的文件必须小于${props.maxSize}Mb`);
  }
  SmartLoading.show();
  try {
    const formData = new FormData();
    formData.append('file', options.file);
    await workExperienceApi.upload(formData, form.id);
    queryWorkExperienceData();
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    SmartLoading.hide();
  }
};


function bireport() {
  if (form.biReport) {
    handleDownload(form.biReport);
  } else {
    message.error('背调报告还未生成');
  }
}

async function viewBireport(){
  if (form.biReport) {
    handleDownload4(form.biReport);
  } else {
    SmartLoading.show();
    try {
      let res = await biApi.generateBiReport(form.id,form.ticketTaskVO.ticketId);
      handleDownload3(res.data);
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      SmartLoading.hide();
    }
  }
}

async function generateBiReport(){
  SmartLoading.show();
  try {
    let res = await biApi.generateBiReport(form.id,form.ticketTaskVO.ticketId);
    handleDownload2(res.data);
  } catch (e) {
    smartSentry.captureError(e);
  } finally {
    SmartLoading.hide();
  }
}

let smsForm = reactive({});
async function smsSend(data){
  smsForm.customerNumber=data.contactsPhone;
  smsForm.contacts=data.contacts;
  smsForm.name=form.name;
  try {
    await clinkApi.smsSend(smsForm);
    message.success('操作成功');
  } catch (e) {
    smartSentry.captureError(e);
  }

}


const clinkFormRef = ref();

function showClinkList(contactsPhone) {
  clinkFormRef.value.show(contactsPhone);
}


async function setBlack() {
  SmartLoading.show();
  try {
    await biApi.setBlack(form.id);
    message.success('操作成功');
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({path: backPath});
  } catch (err) {
    smartSentry.captureError(err);
    SmartLoading.hide();
  }
}

async function cancelBlack() {
  SmartLoading.show();
  try {
    await biApi.cancelBlack(form.id);
    message.success('操作成功');
    SmartLoading.hide();
    useUserStore().closeTagNav(route.meta.id.toString(), false);
    router.push({path: backPath});
  } catch (err) {
    smartSentry.captureError(err);
    SmartLoading.hide();
  }
}
</script>

<style>
.ant-collapse-header {
  font-weight: bolder;
}

.std {
  width: 70% !important;
}
</style>
